# -*- coding:utf-8 -*-
import time
# 1.有四个数字：1、2、3、4，能组成多少个互不相同且无重复数字的三位数？各是多少？
import datetime

'''
for i in range(1,5):
    for j in range(1,5):
        for k in range(1,5):
            if (i!=j)&(j!=k)&(k!=i):
                print 100*i +10*j +k
'''
# 2.企业发放的奖金根据利润提成。利润(I)低于或等于10万元时，奖金可提10%；
# 利润高于10万元，低于20万元时，低于10万元的部分按10%提成，高于10万元的部分，
# 可提成7.5%；20万到40万之间时，高于20万元的部分，可提成5%；
# 40万到60万之间时高于40万元的部分，可提成3%；60万到100万之间时，高于60万元的部分，
# 可提成1.5%，高于100万元时，超过100万元的部分按1%提成，从键盘输入当月利润I，求应发放奖金总数？

'''
arr =[1000000,600000,400000,200000,100000,0]
rat =[0.001,0.0015,0.003,0.005,0.0075,0.01]
m = 0
x = int(raw_input("请输入利润："))
for idx in range(0,6):
    if x > arr[idx]:
        m += (x-arr[idx])*rat[idx]
        print (x-arr[idx])*rat[idx]
        t ="利润：%s,奖金：%s"%(x,m)
print t
'''

# 3. 一个整数，它加上100后是一个完全平方数，再加上168又是一个完全平方数，请问该数是多少？
'''  
     x +100 = n*n
     x+100+168 = m*m
     (m-n)(m+n)=168
     i = m+n  i、j其中之一为偶数
     j = m-n
     m=(i+j)/2 为偶数
     n=(i-j)/2 为偶数
     i*j=168
     j>2
     2<i<168/2+1
'''
'''
for i in range(1,85):
    if 168 % i == 0:
        j = 168/i;
        if (i+j) % 2 == 0 and (i-j) % 2 == 0 and i > j:
            x = ((i-j)/2)**2 - 100
            print (x)
'''

# 4.输入某年某月某日，判断这一天是这一年的第几天？
'''
year = int(raw_input('year:\n'))
month = int(raw_input('month:\n'))
day = int(raw_input('day:\n'))

months =(0,31,59,90,120,151,181,212,243,273,304,334,365)
if 0 < month <= 12:
    sum = months[month-1]
else:
    print "date error!!"
sum += day
leap = 0
if (year % 4 == 0) & (year % 100 != 0) | (year % 400 == 0):
    leap = 1
if (leap == 1) & (month > 2):
    sum = sum +1
print 'it is the %dth day.' % sum
'''
# 5.输入三个整数x,y,z，请把这三个数由小到大输出。
'''
m0 = []
for i in range(3):
    x = int(raw_input('请输入数字:\n'))
    m0.append(x)
m0.sort()
print m0
'''
# 6.斐波那契数列（Fibonacci sequence），又称黄金分割数列，指的是这样一个数列：0、1、1、2、3、5、8、13、21、34、……。
# f(n)=f(n-1)+f(n-2)
'''
def Fib(n):
    if n == 0:
        return 0
    elif n == 1 or n == 2:
        return 1
    else:
        return Fib(n - 1) + Fib(n - 2)
print Fib(10)

def fib(n):
    if n == 0:
        return [1]
    elif n == 1 | n == 2:
        return [1,1]
    fibs = [1,1]
    for n in range(2, n):
        # return fib(n-1)+fib(n-2)
        fibs.append(fibs[n-1] + fibs[n-2])
    return fibs
print fib(80) 
'''
# 7.将一个列表的数据复制到另一个列表中。
# [:] 列表函数
'''
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]
b = a[:]
print b
'''
# 8.输出 9*9 乘法口诀表。程序分析：分行与列考虑，共9行9列，i控制行，j控制列。
'''
for i in range(1,10):
    print
    for j in range(1,i+1):
        print "%d*%d=%d" % (i,j,i*j),
'''
# 9.暂停一秒输出。
'''
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]
for i in range(len(a)):"%y-%m-%d %H:%M:%S" % time.localtime(time.time())
    print a[i]
    time.sleep(1)
'''
# 10.暂停一秒输出，并格式化当前时间。
'''
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597]
for i in range(len(a)):
    print a[i]
    time.sleep(1)
    print time.strftime("%y-%m-%d %H:%M:%S", time.localtime(time.time()))
'''
# 12.判断101-200之间有多少个素数，并输出所有素数。
'''
h = 0
for num in range(101,200):
    for i in range(2,num):
        if (num % i ==0):
            j = num / i
            print "%d = %d * %d" % (num,i,j)
            break
    else:
        print "%d ，是一个素数 " %num
        h += 1
print "101-200 之间总共有 %d 个素数" %h
'''
# 13.打印出所有的"水仙花数"，所谓"水仙花数"是指一个三位数，其各位数字立方和等于该数本身。例如：153是一个"水仙花.计算并输出100-999之间的水仙花数
'''
m = 0
for s in range(100,999):
    i = s % 10
    j = (s / 10) % 10
    k = s/100
    if (s == i*i*i +j*j*j +k*k*k):
        print s
        m +=1
print '总共有 %d 个水仙花数' %m
'''
# 14.将一个正整数分解质因数(1)如果这个质数恰等于n，则说明分解质因数的过程已经结束，打印出即可。(2)如果n<>k，但n能被k整除，则应打印出k的值，并用n除以k的商,作为新的正整数你n,重复执行第一步。(3)如果n不能被k整除，则用k+1作为k的值,重复执行第一步。
'''
def fjzys(n):
    n = int(n)
    for i in range(2,n/2+1):
        if n % i == 0:
            print i,'*'
        else:
            continue
        return fjzys(n/i)
    print n,

fjzys(12050)
'''
# 15.利用条件运算符的嵌套来完成此题：学习成绩>=90分的同学用A表示，60-89分之间的用B表示，60分以下的用C表示
'''
score = int(raw_input("请输入分数：\n"))
if score >= 90:
    grade = 'A'
elif score >= 60:
    grade = 'B'
else:
    grade = 'C'
print '%d 属于 %s' %(score,grade)
'''
# 16.输出指定格式的日期。datetime
'''
if __name__ =='__main__':
# 输出今日日期，格式为 dd/mm/yyyy。strftime() 方法
print(datetime.date.today().strftime('%d/%m/%Y'))
# 创建日期对象
BirthDate = datetime.date(1990,1,1)
print (BirthDate.strftime('%d/%m/%Y'))
# 日期算术运算
BirthNextDate = BirthDate + datetime.timedelta(days=1)
print (BirthNextDate.strftime('%d/%m/%Y'))
BirthBeforDate = BirthDate + datetime.timedelta(days=-1)
print (BirthBeforDate.strftime('%d/%m/%Y'))
# 日期替换、输出下一个生日
NextBirthDate = BirthDate.replace(year = BirthDate.year+1)
print (NextBirthDate.strftime('%Y-%m-%d'))
'''
# 17.输入一行字符，分别统计出其中英文字母、空格、数字和其它字符的个数。
'''
import string
s = raw_input('请输入一个字符串\n')
letters = 0
space = 0
digit = 0
other = 0
i = 0
while i < len(s):
    c = s[i]
    if c.isalpha():
        letters += 1
    elif c.isdigit():
        digit += 1
    elif c.isspace():
        space += 1
    else:
        other += 1
    i +=1
print 'char = %d，digit = %d, space = %d,other =%d' % (letters,digit,space,other)
'''
# 18.求s=a+aa+aaa+aaaa+aa...a的值，其中a是一个数字。
# 例如2+22+222+2222+22222(此时共有5个数相加)，几个数相加由键盘控制。
'''
n = int(raw_input('n = '))
a = int(raw_input('a = '))
An = 0
Sn = []
for count in range(n):
    An = An +a
    a = a*10
    Sn.append(An)
    print An
Sn = reduce(lambda x,y : x+y ,Sn)
print '总和是%d' %Sn
'''
# 19.一个数如果恰好等于它的因子之和，这个数就称为"完数"。例如6=1＋2＋3.编程找出1000以内的所有完数
'''
for m in range(1,1000):
    k = []
    # 分解因数
    for i in range(1, m+1):
        if m % i == 0:
            k.append(i)
        else:
            # continue
        AA = sum(k)
        if m == AA:
            print "完数%d，因数%s" %(m,k)
print '_______________'
#  分解质因数
def zys(l):
    l = int(l)
    LL =[]
    AA0=1
    for t in range(2,l/2+1):
        if l % t == 0:
            LL.append(t)
        else:
            continue
        print t,"*"
        return zys(l/t)
        # for i0 in range(len(LL)):
        #     AA0 *= LL[i0]
        #     i0 += 1
        #     print '%d=%d*%d' % (AA0,LL[i0],LL[i0+1])
zys(1256)
'''
# 20.一球从100米高度自由落下，每次落地后反跳回原高度的一半；再落下，求它在第10次落地时，共经过多少米？第10次反弹多高？
'''
height0 =[]  # 高度
s =[]  # 路程
height =100.0 # 始高度100
tim =10
for i in range(1,tim+1):
    if i ==1:
        s.append(height)
    else:
        s.append(2 * height)
    height /= 2
    height0.append(height)
print '总高度:s ={0}'.format(sum(s))
print '第10次反弹的高度：height0 ={0}'.format(height0[-1])
'''

# 21.猴子吃桃问题：猴子第一天摘下若干个桃子，当即吃了一半，还不瘾，又多吃了一个第二天早上又将剩下的桃子吃掉一半，又多吃了一个。
# 以后每天早上都吃了前一天剩下的一半零一个。到第10天早上想再吃时，见只剩下一个桃子了。求第一天共摘了多少。
'''
s0 = 1
k = []
for day in range(1,11):
    s0 = (s0+1)*2
    k.append(s0)
    k.reverse()
    c = sorted(k,reverse=True)
print s0,c
'''
# 22.打印出如下图案（菱形）:
'''
rows = int (raw_input('输入行数'))
# print "等腰直角三角形1"
# for i in range(0,rows):
#     for k in range(0,rows-i):
#         print "*",
#         k +=1
#     i+=1
#     print '\n'

## 打印实心等边三角形
# for i in range(0,rows):
#     for j in range(0,rows-i):
#         print " "
#         j +=1
#     for k in range(0,2*i-1):
#         if k ==0 or k==2*i-2 or i==rows:
#             if i==rows:
#                 if k%2==0:
#                     print "*"
#                 else:
#                     print " "
#             else:
#                 print "*"
#         else:
#             print " "
#         k +=1
#     print "\n"
#     i +=1

# print "打印空心等边三角形，这里去掉if-else条件判断就是实心的"
# for i in range(0, rows + 1):#变量i控制行数
#     for j in range(0, rows - i):#(1,rows-i)
#         print " ",
#         j += 1
#     for k in range(0, 2 * i - 1):#(1,2*i)
#         if k == 0 or k == 2 * i - 2 or i == rows:
#             if i == rows:
#                 if k % 2 == 0:#因为第一个数是从0开始的，所以要是偶数打印*，奇数打印空格
#                     print "*",
#                 else:
#                     print " ", #注意这里的","，一定不能省略，可以起到不换行的作用
#             else:
#                print "*",
#         else:
#             print " ",
#         k += 1
#     print "\n"
#     i += 1
#打印菱形
print "打印空心等菱形，这里去掉if-else条件判断就是实心的"
for i in range(rows):#变量i控制行数
    for j in range(rows - i):#(1,rows-i)
        print " ",
        j += 1
    for k in range(2 * i - 1):#(1,2*i)
        if k == 0 or k == 2 * i - 2:
            print "*",
        else:
            print " ",
        k += 1
    print "\n"
    i += 1
    #菱形的下半部分
for i in range(rows):
    for j in range(i):#(1,rows-i)
        print " ",
        j += 1
    for k in range(2 * (rows - i) - 1):#(1,2*i)
        if k == 0 or k == 2 * (rows - i) - 2:
            print "*",
        else:
            print " ",
        k += 1
    print "\n"
    i += 1
'''
# 23.2/1，3/2，5/3，8/5，13/8，21/13...求出这个数列的前20项之和。
'''
Sn = 0.0
a1=2.0
b1=1.0
for i in range(1,21):
    Sn += a1/b1
    a1,b1 = a1+b1,a1
print Sn
'''

# 24.求1+2!+3!+...+20!的和。
'''
# Sn = 0
# r =1
# Tn=[]
# for n in range(1,21):
#      r *= n
#      Sn += r
#      Tn.append(Sn)
# print Sn,Tn

##(2)定义递归函数求阶乘后在求和
def recursion(n):
    if n == 0:
        return 1
    else:
        return n * recursion(n-1)
Tn = []
for i in range(1, 21):
    T = recursion(i)
    Tn.append(T)
Sn = sum(Tn)
print Tn
print Sn
'''
# 26.利用递归方法求5!。
'''
def fun(n):
    if n ==0:
        return 1
    else:
        return n * fun(n-1)
print fun(9)
'''
# 27.利用递归函数调用方式，将所输入的5个字符，以相反顺序打印出来。
'''
s = raw_input("请输入字符串s:")
def Putout(s,l):
        if l == 0:
            return
        print s[l-1]
        Putout(s,l-1)
l = len(s)
Putout(s,l)
'''
# 28.有5个人坐在一起，问第五个人多少岁？他说比第4个人大2岁。问第4个人岁数，他说比第3个人大2岁。问第三个人，又说比第2人大两岁。
# 问第2个人，说比第一个人大两岁。最后问第一个人，他说是10岁。请问第五个人多大？
'''
def Countage(n):
    if n == 1:
        Age = 10
    else:
        Age = Countage(n - 1) + 2
    return Age
print Countage(5)
'''
# 29.给一个不多于5位的正整数，要求：一、求它是几位数，二、逆序打印出各位数字。
'''
A = int(raw_input("请输入一个5位正整数："))
a = A /10000
b =(A%10000)/1000
c =(A%1000)/100
d =(A%100)/10
e =A%10
if a!=0:
    print '5 位数:',e,d,c,b,a
elif b !=0:
    print '4 位数:', e, d, c, b,
elif c!=0:
    print '3 位数:', e, d, c,
elif d !=0:
    print '2 位数:', e, d,
else:
    print '1 位数:', e,
'''
# 30.一个5位数，判断它是不是回文数。即12321是回文数，个位与万位相同，十位与千位相同。
'''
B = int(raw_input("请输入一个正整数："))
s = str(B)
mm = True
for n in range(len(s)/2):
    if s[n] != s[-n-1]:
        mm = False
    else:
        mm = True
if mm :
    print '%d:是一个回文数' % B
else:
    print '%d:不是一个回文数' % B
'''
# 31.请输入星期几的第一个字母来判断一下是星期几，如果第一个字母一样，则继续判断第二个字母。
'''
letter = raw_input("请输入字第一个字母：")
if letter == 'T'or't':
    letter = raw_input("请输入第二个字母：")
    if letter == 'h'or'H':
        print 'Thursday'
    elif letter == 'u'or'U':
        print 'Tuesday'
    else:
        print '输入日期有误'
elif letter =='S'or's':
    letter = raw_input("请输入第二个字母：")
    if letter == 'u'or'U':
        print 'Sunday'
    elif letter == 'a'or'A':
        print 'Saturday'
    else:
        print '输入日期有误'
elif letter =='M'or'm':
    print 'Monday'
elif letter =='W'or'w':
    print "Wednesday"
elif letter =="F"or'f':
    print "Friday"
else:
    print '输入日期有误'
'''
# 32.按相反的顺序输出列表的值。
'''
H0 = []
for i in range(4):
    h = int(raw_input("请输入一个数："))
    H0.append(h)
    H0.reverse()
    C = sorted(H0,reverse=True)
print H0
'''
# 33.按逗号分隔列表。
'''
L = [15, 1265, 165, 5465]
print ','.join(str(n) for n in L)
li = ["11", "22", "33","44","55","66"]
print '-'.join(li)
'''
# 34.练习函数调用。
'''
def function(a,b):
    for n in range(6):
        a+=1
        b+=1
        print a**b
        print 'Hello World!!'
        if a==9 & b ==9:
            break
        else:
            continue
def fun():
    for i in range(5):
        function(1,1)
if __name__ == '__main__':
    fun()
'''
# 35.文本颜色设置。
# 36.求100之内的素数。
'''
k = []
min = int(input("请输入最小数："))
max = int(input("请输入最大数："))
is_ss = True
for num in range(min, max + 1):
        for i in range(2, num/2+1):
            if (num % i) == 0:
                break
        else:
            print num
            k.append(num)
print sum(k), k
'''
# 37.对10个数进行排序。
'''
LL=[]
print "请输入10个数字"
for i in range(1,11):
    LL.append(int(raw_input("请输入第%d个数字:"%i)))
    
# LL0 = [12, 32, 10, 25, 230, 1, 2, 60, 654, 159]
# for i in range(len(LL0)):
#     for j in range(len(LL0)):
#         if (LL0[i] >= LL0[j]):
#             LL0[i],LL0[j] = LL0[j],LL0[i]
# print "冒泡排序之后输出：",LL0

print "从大到小排序后输出",sorted(LL,reverse=True)
print "从 小到大排序后输出",sorted(LL,reverse=True)
'''
# 38.求一个3*3矩阵主对角线元素之和。
'''
sum = 0
sum1 =0
MM =[]
for i in range(3):
    temp =[]
    for j in range(3):
        temp.append(int(raw_input("请输入数字")))
    # print temp
    MM.append(temp)
for m in range(3):
# for m,n in range(3):
#     if m == n:
#         print MM[m][m]
#     else:
#         break
    sum += MM[m][2-m]
    sum1 +=MM[m][m]
print "负对角线的和：%d,主对角线的和:%d,矩阵MM:%s" %(sum,sum1,MM)
# matrix = [[ i for i in range(3)] for i in range(3)]
# print matrix
'''
# 39.有一个已经排好序的数组。现输入一个数，要求按原来的规律将它插入数组中
'''
a = [1,4,6,9,13,16,19,28,40,100,0]
print '原始列表:'
for i in range(len(a)):
    print a[i],
number = int(raw_input("\n插入一个数字:\n"))
end = a[9]
if number > end:
    a[10] = number
else:
    for i in range(10):
        if a[i] > number:
            temp1 = a[i]
            a[i] = number
            for j in range(i + 1,11):
                temp2 = a[j]
                a[j] = temp1
                temp1 = temp2
            break
print '排序后列表:',a
'''
# a = [1,4,6,9,13,16,19,28,40,100,253]
# number = int(raw_input("\n插入一个数字:\n"))
# a.insert(3,number)
# print sorted(a,reverse=False)
# 40.将一个数组逆序输出
'''
if __name__ =="__main__":
    a = [1, 4, 6, 9, 13, 16, 19, 28, 40, 100, 253]
    N = len(a)
    print a
    for i in range(len(a)/2 +1):
        a[i],a[N-i-1] = a[N-i-1],a[i]
    print a
    # print sorted(a,reverse=True)
'''
# 41.模仿静态变量的用法
'''
# class statics:
#     Var = 5
#     def staticVarfun(self):
#         self.Var += 1
#         print self.Var
# print statics.Var
# a = statics()
# for i in range(5):
#     print a.staticVarfun()
def varfun(var1):
    print "var1 =%d "% var1
    var1 +=1
if __name__=="__main__":
    for i in range(3):
        print varfun(var1=1)
'''
# 42.题目：学习使用auto定义变量的用法。
'''
num = 2
def autofun1():
    num = 10
    print 'internal block num = %d' % num
    num += 1
    print "____"
for i in range(3):
    print '数字num:%d', num
    num += 1
autofun1()
'''
# 43.模仿静态变量(statics)另一案例。演示一个python作用域使用方法
'''
class Num:
    nNum =1
    def statics(self):
        self.nNum +=10
        print "局部nNum =%d" % self.nNum
if __name__ =="__main__":
    nNum =1
    inst = Num()
    for i in range(4):
        nNum +=1
        print nNum
        inst.statics()
# class Num:
#     nNum = 1
#     def inc(self):
#         self.nNum += 1
#         print 'nNum = %d' % self.nNum
#
# if __name__ == '__main__':
#     nNum = 2
#     inst = Num()
#     for i in range(3):
#         nNum += 1
#         print 'The num = %d' % nNum
#         inst.inc()
'''
# 44.两个 3 行 3 列的矩阵，实现其对应位置的数据相加，并返回一个新矩阵：
'''
X = [[12,7,3],[4 ,5,6],[7 ,8,9]]
Y = [[5,8,1],[6,7,3],[4,5,9]]
result=[[0,0,0],[0,0,0],[0,0,0]]

for i in range(len(X)):
    for j in range(len(Y)):
        for k in range(len(result)):
            if i == j:
                result[k][k]=X[i][i] +Y[j][j]
    for k in result:
        print k
'''
# 45.统计 1 到 100 之和。
'''
sum =0
for i  in range(1,101):
    sum += i
print sum
'''
# 46.求输入数字的平方，如果平方运算后小于 50 则退出。
'''
def fun0(x):
    y = x * x
    return y
print "平方运算后小于 50,退出运算"
again = 1
while again:
    temp = int(raw_input("请输入数字："))
    print "运算结果为：%d" % (fun0(temp))
    if fun0(temp) > 50:
        again = 1
    else:
        again = 0
'''
# 47.两个变量值互换
'''
def exchange(a,b):
    a,b = b,a
    return(a,b)
if __name__=="__main__":
    a=10
    b=20
    print "互换前：a = %d" %a
    print "互换前：b = %d" %b
    a,b =exchange(a,b)
    print "互换后：a = %d" % a
    print "互换后：b = %d" % b
'''
# 48.比较数字大小。
'''
if __name__ =="__main__":
    i = 20
    j = 10
    if i>j :
        print "%d 大于%d "%(i,j)
    elif i == j :
        print "%d 等于%d "%(i,j)
    else:
        print "%d 小于%d "%(i,j)

'''
# 49.使用lambda来创建匿名函数
'''
n = 6
print reduce(lambda x,y:x*y,range(1,n+1))
print reduce(lambda x,y:x*y,[1,60,8,45,7,6,9])
'''

# 50.输出一个随机数
# import random
# print random.randint(4,96)

# 51.题目：学习使用按位与 & 。
'''''
if __name__ == '__main__':
    a = 077
    b = a & 3
    print 'a & b = %d' % b
    b &= 7
    print 'a & b = %d' % b
    print 'a|b=%d'%b
    c=5
    d=7564
    print c<<2
    print d>>5

# 十进制数转换二进制数
# coding=utf-8
dec = int(input("输入数字："))

print("十进制数为：", dec)
print("转换为二进制为：", bin(dec))
print("转换为八进制为：", oct(dec))
print("转换为十六进制为：", hex(dec))



if __name__ == '__main__':
    # a = 0772
    # b = a | 3
    # print 'a | b is %d' % b
    # b |= 7
    # print 'a | b is %d' % b
    # aa = 0707
    # bb = aa ^ 3
    # print 'The aa ^ 3 = %d' % bb
    # b ^= 7
    # print 'The aa ^ bb = %d' % bb
    # a0 = int(raw_input('input a number:\n'))
    # b0 = a0 >> 4
    # c0 = ~(~0 << 4)
    # d0 = b0 & c0
    # print '%o\t%o' % (a0, d0)

    a = 60  # 60 = 0011 1100
    b = 13  # 13 = 0000 1101
    c = 0

    c = a & b;  # 12 = 0000 1100
    print "1 - c 的值为：", c

    c = a | b;  # 61 = 0011 1101
    print "2 - c 的值为：", c

    c = a ^ b;  # 49 = 0011 0001
    print "3 - c 的值为：", c

    c = ~a;  # -61 = 1100 0011
    print "4 - c 的值为：", c

    c = a << 2;  # 240 = 1111 0000
    print "5 - c 的值为：", c

    c = a >> 2;  # 15 = 0000 1111
    print "6 - c 的值为：", c
'''

# 54.取一个整数a从右端开始的4〜7位。
'''
程序分析：可以这样考虑： 
(1)先使a右移4位。 
(2)设置一个低4位全为1,其余全为0的数。可用~(~0<<4) 
(3)将上面二者进行&运算。'''
# if __name__ == '__main__':
#     a = int(raw_input('input a number:\n'))
#     b = a >> 4
#     c = ~a
#     d = b & c
#     print '%o\t%o' %(a,d)
# 56.画图，学用circle画圆形
'''
import numpy as np
# import matplotlib as mp1
# import  matplotlib.pylot as plt
import time
from Tkinter import *

can = Canvas(width=800, height=600, bg='yellow')
can.pack(expand=YES, fill=BOTH)
k = 1
j = 1
for i in range(0, 26):
    can.create_oval(310 - k, 250 - k, 310 + k, 250 + k, width=1)
    k += j
    j += 0.3
mainloop()
'''
'''
if __name__ =="__main__":
    root =Tk()
    root.title("图形")
    Cr =Canvas(width =1020,height =1080,bg="white")
    # Cr.pack(expend=YES,fill=BOTH)
x =10
y =10
x1 =800
y1 =600
r=600
a=80
b=90
a0=550
b0=500
w1=90
h1=60
print '画矩形'
Cr.create_rectangle(x,y,x1,y1,fill="red",outline="blue",width=10)
print"画圆"
Cr.create_oval(x,y,r,r,outline="blue",width=5)
print "画椭圆"
Cr.create_oval(x,y,a0,b0,outline="white",width=5)
print "画线"
Cr.create_line(a,b,a0,b0,w1,h1,fill ='green',width=5)
a1 =100
b1=100
r0=60
w1=90
h1=60
Cr.create_oval(a1-r0,b1-r0,w1,h1,width=1,fill='yellow')
Cr.create_arc(100,100,300,300,start = 0,extent = 260,fill='yellow')
Cr.pack()
root.mainloop()
'''
'''
from Tkinter import *
root = Tk()
# root.geometry("1000*1000")
can = Canvas(width=600,height =600,bg="white")
# can.pack_slaves(expect='YES',fill=BOTH)
Label(root,text='pack').pack
x =163
y = 163
x0 =500
y0=500
# 画虚线
for i in range(6):
    can.create_line(x,y,x,y0,fill="green",dash=(4,4),width='2')
    x += 50
a = 263
b = 263
a0 = 275
b0 = 275
for k in range(10):
    can.create_line(a,b,a,b0,fill="red",width='4')
    a -=30
    b -=30
    a0 +=30
    b0 +=30
a2=273
b2 = 263
a20 = 300
b20 = 300
for j in range(10):
    can.create_line(a2,b2,a2,b20,width="5")
    a2 +=30
    b2 +=30
    a20 +=30
    b20 +=30
Tr = can.create_rectangle(0,0,50,50,outline='purple',stipple='gray12',fill="black",)
rt=can.create_rectangle(0,0,50,50,fill='black',outline='purple',stipple='gray12')

# 三角形
can.create_polygon((10,100,10,180,100,180),fill="blue",tags=("r1","r2",'r3'))
can.create_text((150,120),text='三角形',anchor=E)
def printRect(event):
    print 'rectangle'
def printLine(event):
    print 'line'
can.tag_bind("r1",'<Button-1>',printRect)
can.tag_bind("r2",'<Button-3>',printLine)
can.create_line(40,100,40,500,fill="red",arrow="first")
can.create_line(40,500,500,500,fill="blue",arrow="last")
can.pack()
#coords将某部分移动到另一区域、同move
# can.coords(Tr,300,100,350,150)
can.move(Tr,300,100)
root.mainloop()
'''
# 57.画图，学用line画直线。
'''
if __name__=='__main__':
    from Tkinter import *
    root = Tk()
    canvas = Canvas(width=300,height=300,bg='green')
    canvas.pack(expand=YES, fill=BOTH)
    x0 = 100
    y0 = 100
    y1 = 150
    x1 = 150
    for i in range(19):
        canvas.create_line(x0,y0,x0,y1,width=1.5,fill='red')
        x0 = x0-5
        y0 = y0+5
        x1 = x1+5
    x0 = 150
    y1 = 150
    y0 = 150
    for i in range(21):
        canvas.create_line(x0, y0, x0, y1, fill='red')
        x0 += 5
        y1 -= 5
    root.mainloop()
    '''
# 58.画图，学用rectangle画方形。　
# (left ，top )为矩形的左上坐标，(right,bottom)为矩形的右下坐标，两者可确定一个矩形的大小
'''
if __name__=="__main__":
    from Tkinter import *
    root =Tk()
    root.title('practice')
    canvas=Canvas(width =300,height=300,bg='yellow')
    x0 = 150
    y0 = 150
    y1 = 150
    x1 = 150
    for i in range(20):
        canvas.create_rectangle(x0,y0,x1,y1,width=1)
        x0 = x0-5
        y0 = y0-5
        y1 = y1+5
        x1 = x1+5
    canvas.pack()
    root.mainloop()
'''
# 59.计算字符串长度。　　
# str ='9080jklh    &&& *(&(msd'
# A ='HSADKH09-09NKBK'
# X= A.__len__()
# print len(str)
# print X
# 61.杨辉三角
'''
if __name__=='__main__':
    a=[]
    for i in range(10):
        a.append([])
        for j in range(10):
            a[i].append(0)
    for i in range(10):
        a[i][0]=1
        a[i][i]=1
    for i in range(2,10):
        for j in range(1,i):
            a[i][j]=a[i-1][j-1]+a[i-1][j]
    from sys import stdout
    for i in range(10):
        for j in range(i+1):
            stdout.write(str(a[i][j]))
            stdout.write(' ')
        print
'''
# 62.find 查找字符串输出首次出现的位置
# str1='n东方大道多多多多sdlnmkasdfsdfmsdsdl;jklksd'
# str2='sd'
# print str1.find(str2)
# 63.画椭圆
# if __name__=="__main__":
#     from Tkinter import *
#     x=360
#     y=160
#     m=y-30
#     n=x-30
#     canvas=Canvas(width=400,height=600,bg='white')
#     for i in range(20):
#         canvas.create_oval(x,y,m,n)
#         m-=5
#         n+=5
#     canvas.pack()
#     mainloop()
# 64.利用ellipse 和 rectangle 画图
# if __name__=='__main__':
#     from Tkinter import *
#     canvas=Canvas(width=400,height=600,bg='white')
#     left=20
#     right=50
#     top=50
#     num =15
#     for i in range(num):
#         canvas.create_oval(250-right,250-left,250+right,250+left)
#         canvas.create_rectangle(20-2*i,20-2*i,10*(i+1),10*(i+1))
#         right += 5
#         left += 5
#         top += 10
#     canvas.pack()
#     mainloop()
# 66.输入3个数a,b,c，按大小顺序输出。
# if __name__ == '__main__':
#     n1 = int(raw_input('n1 = :\n'))
#     n2 = int(raw_input('n2 = :\n'))
#     n3 = int(raw_input('n3 = :\n'))
#
#     def swap(p1, p2):
#         return p2, p1
#
#     if n1 > n2: n1, n2 = swap(n1, n2)
#     if n1 > n3: n1, n3 = swap(n1, n3)
#     if n2 > n3: n2, n3 = swap(n2, n3)
#
#     print n1, n2, n3
# 67.写一个函数，求一个字符串的长度，在main函数中输入字符串，并输出其长度。
# if __name__=="__main__":
#     s= raw_input('please input a string:\n')
#     print 'the string has %d characters.' % len(s)
# 68.创建一个链表。
# if __name__ == "__main__":
#     pt=[]
#     for i in range(5):
#         num = int(raw_input('please input a number:\n'))
#         pt.append(num)
#     print '列表原顺序：%s' %pt
#     print sorted(pt,reverse=False) # 从小到大
#     print sorted(pt,reverse=True) # 从大到小
#     pt.reverse()   # 反向输出一个链表
#     print pt
#     print list(reversed(pt))  # 将列表中所有元素反着排列，位置在前的变成位置在后的
# 73.反向输出一个链表。
# if __name__ == '__main__':
#     ptr = []
#     for i in range(5):
#         num = int(raw_input('please input a number:\n'))
#         ptr.append(num)
#     print ptr
#     ptr.reverse()
#     print ptr
# 74.列表排序及连接
# if __name__ == "__main__":
#     l= [5165, 1900, 21065, 2065,2165, 2065, 15000000, 10005]
#     l0 = [55, 10, 25,65, 0,15, 5, 15,0,0,120, 1500]
#     # print l0.count(0)
#     # print l0.pop(0)
#     if 0 in l0:
#         l0.remove(0)
#     print l0
    # ll0=set(l0)
    # print ll0
    # l0.insert(2,[2,26,45,])
    # print l0
    # print sorted(l0,reverse=True)
    # l0.sort()
    # print l0
    # # print l+l0
    # l.extend(l0)
    # print l
# 75.编写一个函数，输入n为偶数时，
# 调用函数求1/2+1/4+...+1/n,当输入n为奇数时，调用函数1/1+1/3+...+1/n
# def sumdaoshu(n):
#     s= 0.0
#     if n % 2 ==0:
#         for i in range(1,n+1,1):
#             s+=1.0/i
#         return s
#     else:
#         for i in range(2,n+1,2):
#             s+=1.0/i
#         return s
# if __name__=="__main__":
#     m = sumdaoshu(int(raw_input("请输入一个正整数")))
#     print "%.9f" %m
# 77.循环输出列表
# if __name__ == '__main__':
#     s = ["man","woman","girl","boy","sister"]
#     for i in range(len(s)):
#         print s[i]
#     s.insert(2,'fdsfs')
#     print s
# 78.找到年龄最大的人，并输出。请找出程序中有什么问题。
# if __name__=='__main__':
#     person = {"li": 18, "wang": 50, "zhang": 20, "sun": 22}
#     def findMax(dict):
#         max_age=0
#         for key,value in dict.items():
#             if value > max_age:
#                 max_age = value
#                 name= key
#         print "%s,%d" %(name,max_age)
# findMax(person)
# 79.字符串排序
# str1='asfjiod'
# str2='nijoi'
# str3='hfjsd'
# print str1,str2,str3
# if str1 >str2:
#     str1,str2=str2,str1
# if str1 >str3:
#     str1,str3=str3,str1
# if str2 > str3:
#     str2,str3=str3,str2
# print str1, str2, str3
# print bin(564)
# print oct(555505335)
# print hex(0235713514745204141L)
# 83.求0—7所能组成的奇数个数。
# s1 =0
# for i in range(0,8):
#     if i %2!=0:
#         s1+=1
# # print s1
# if __name__ == '__main__':
#     s1=4
#     sum =0
#     for k in range(2,9):
#         if k <=2:
#             s1*=7
#         else:
#             s1*=8
#         sum+= s1
#     print sum
# 84.连接字符串。
# delimiter = 'AA,CC'
# mylist = ['Brazil', 'Russia', 'India', 'China']
# # print delimiter.join(mylist)
# print '%s%s'%(delimiter,mylist)
# # print mylist+delimiter
# mylist1 = ['Brazil', 'Russia', 'India', 'China']
# mylist2 = ['Brazil', 'rrr', 'India', 'China']
# m= mylist1+mylist2
# print m
# print set(m)
# print tuple('121')
# print dict((('a',1),('b',2)))
# print (zip(mylist1,mylist2))
# 85.输入一个奇数，然后判断最少几个 9 除于该数的结果为整数。
# x= int(input("请输入一个正整数"))
# n=1
# sum=9
# s =9
# count=1
# while n !=0:
#     if sum % x == 0:
#         n = 0
#     else:
#         s *=10
#         sum += s
#         count += 1
# print '%d 个9 能被%d整除' %(count,x)

# 86.字符串的链接
# a='asfjiod'
# b='nijoi'
# l1=[1,11,5,4,21,12465,]
# l0=[152,6,154,56,3256,]
# print a+b
# l0.extend(l1)
# print l0
# 87.结构体变量 （欠）
# 88.读取7个数（1—50）的整数值，每读取一个值，程序打印出该值个数的＊。
# if __name__=='__main__':
#     N=1
#     while N<7:
#         x = input("输入正整数")
#         if x>1 & x<50:
#             print x
#         print x*'*'
#         N +=1
# 89.某个公司采用公用电话传递数据，
# 数据是四位的整数，在传递过程中是加密的，
# 加密规则如下：每位数字都加上5,然后用和除以10的余数代替该数字，
# 再将第一位和第四位交换，第二位和第三位交换。
# if __name__=="__main__":
#     M=int(raw_input("请输入一个四位的正整数"))
#     M0=[]
#     M0.append(M/1000) # 取千位
#     M0.append((M/100)%10) # 取百位
#     M0.append((M %100)/10) # 取十位
#     M0.append(M %10)  # 取个位
#     print'依次取出各个位的数',M0
#     for i in range(len(M0)):
#         M0[i]+=5
#     print '各个位加5之后',M0
#     M0[0],M0[-1] = M0[-1],M0[0]
#     M0[1],M0[2] = M0[2],M0[1]
#     print '加密之后输出的结果', M0
# 90.列表操作
# list=[10086,'中国移动',[1,2,4,5]]
# print len(list)
# print list[1:]  # 从第二个开始取
# list.append('i\'m new here!')
# print list
# print list[-1]
# print list.pop()
# print list.pop(1)
# matrix = [[1, 2, 3],
#           [4, 5, 6],
#           [7, 8, 9]]
# print matrix
# print matrix[2]
# col2=[row[1] for row in matrix]
# print col2
# col2even=[row[1] for row in matrix if row[1]%2==0 ]
# print col2even
# 91.92 时间枚举
# if __name__=='__main__':
#     import time
#     str = '2016-04-23 12:34:54'
#     print time.time()  # 当前时间戳
#     print time.ctime()  # 星期、月份、day、时分秒、年
#     print time.strptime(str,'%Y-%m-%d %X')
#     print time.asctime()
#     print time.asctime(time.localtime(time.time()))
#     print time.localtime()
#     print time.gmtime()
#     print time.gmtime(time.time())
#     star = time.time()
#     for i in range(3000):
#         print i
#     end =time.time()
#     print end-star
# 93.时间枚举3
# if __name__ == '__main__':
#     import time
#     start = time.clock()
#     for i in range(10000):
#         print i
#     end = time.clock()
#     print 'different is %6.3f' % (end - start)
# 95.字符串日期转换为易读的日期格式。
# from dateutil import parser
# dt =parser.parse("Aug 28 2015 12:00AM")
# print dt
#
# str1='mklfdmgmamgskmfsmdssmdfkl;s'
# str2='m'
# print str1.count(str2)

# 96.文件的写入
# from sys import stdout
# filename = raw_input("请输入内容：\n")
# fp =open('D:/filename','w')
# ch = raw_input('输入字符串:\n')
# while ch!="#":
#     fp.write(ch)
# fp.close()
# 97.从键盘输入一个字符串，将小写字母全部转换成
# 大写字母，然后输出到一个磁盘文件"test"中保存。
# if __name__=='__main__':
#     fp=open('D:/test.txt','w')
#     ch=raw_input("请输入内容")
#     ch=ch.upper()
#     ch1=ch.lower()
#     ch2=ch.capitalize()   # 首字母大写
#     ch3=ch.title() # 单次的每个首字母大写
#     fp.write(ch3)
#     fp.close()
# 99.有两个磁盘文件A和B,各存放一行字母,要求把这两个文
# 件中的信息合并(按字母顺序排列), 输出到一个新文件C中。
# if __name__=='__main__':
#     def readfile(filename):
#         fp =open('D:/filename','r')
#         a = fp.read()
#         fp.close()
#         return a
#     l=list(readfile('test.txt')+readfile('filename'))
#     l.sort()
#     # s=''.join(l)
#     s0=''
#     s=s0.join(l)
#     t=open('D:/testtest.txt','w')
#     t.write(s)
#     t.close()
# 100.列表转换为字典。
# i = ['a', 'b','g']
# l = [1, 2,24]
# print dict(zip(i,l))
# l1=[1,2,3,6,87,3,465,15,]
# l2=['aa','bb','cc','dd','ee','ff',45,[1,5,5,6]]
# print dict(zip(l1,l2))
# # 101. 获取 100 以内的质数。
# import math
# def func(n):
#     return filter(lambda x: not [x%i
#                 for i in range(2,int(math.sqrt(x)+1))
#                         if x%i==0],
#                   range(2,n+1))
# print func(100)

# print pow(10,3)
# print pow(10,3,5)
# l =[150,15,415,245,153,1553,2]
# print (list(reversed(l)))
# print sorted(l)
# print round(5.865)
# st='ksajfdkmsmdmsdasdfkgjierjgiejrgeriwgjcn'
# # print st[1:16:2]
# x=slice(1,16,2)
# print x.start
# print x.stop
# print x.step
# print st[x]
#
#
# dict={'zhangsan':564,"lisi":5643,'wangwu':463,'zhaosi':4646}
# print zip(dict.values(),dict.keys())
# print sorted(zip(dict.values(),dict.keys()))
# print sorted(dict,key=lambda key:dict[key])
# print ">>>>>>>>>>>"
#
# people=[{"name":'zhangsan','age':165},
#         {'name':"lisi",'age':5643},
#         {'name':'wangwu','age':463},
#         {'name':'zhaosi','age':4646}]
# print sorted(people,key=lambda dic:dic['age'])
# print min(people,key=lambda dic:dic['age'])
# print max(people,key=lambda dic:dic['age'])



